new Vue({
  el: "#app",
  data() {
    return {
      a: {},
      ye: 1,
      loading: false,
      IMGlj: "https://www.kdddy.cn/Image/",
      three: [
        // {
        //   lable: " ",
        //   children: [{}],
        // },
      ],
      restaurants: [],
      state: "",
      timeout: null,
      defaultProps: {
        children: "children",
        label: "label",
      },
      UserID: decodeURI($.cookie("use")),
      form: {
        SQLSerialNumber: "A_business_article_specifications3",
        PaginationNumber: 1, //页数
        RowAmount: 10, //每页数据条数
        Condition: "",
        ExtensionCondition: "",
        Article_Name: "",
        Brand_SerialNumber: "",
        Shelf: "",
        Supplier_Name: "",
      },
      total: 0,
      count: 0,
      tableData: [],
      brand: [], //商品品牌
      // loading: false,
      dialogVisible: false,
      Article_SerialNumber: "",
      multipleSelection: [],
      Enterprise_Number:'',
    };
  },
  mounted() {
    // this.restaurants = this.loadAll();
    this.dhcph(); //前端分页
    this.ArticleTree();
  },
  methods: {
    isButtonEnabled(row) {
      // 根据行的数据决定按钮是否可用
      // 例如，只有年龄大于25时按钮才可用
      if (row.Refusal_Reason !== "") return true;
    },
    isButtonEnabled1(row) {
      // 根据行的数据决定按钮是否可用
      // 例如，只有年龄大于25时按钮才可用
      if (row.Row_Status == "01" || row.Row_Status == "1") return true;
    },
    isButtonEnabled2(row) {
      // 根据行的数据决定按钮是否可用
      // 例如，只有年龄大于25时按钮才可用
      if (row.Row_Status == "1") return true;
    },
    // 当点击审核按钮时，先保存当前行数据
    showAuditDropdown(row) {
      this.currentRow = row;
      // 这里不需要直接处理审核逻辑，让下拉菜单的command来处理
    },
    // 处理下拉菜单命令
    handleCommand(command) {
      const _this = this;
      if (command === "a") {
        // 通过操作
        console.log("通过审核:", this.currentRow);
        this.currentRow.Refusal_Reason = "";
        this.currentRow.Row_Status = "01";
        console.log("通过审核:", this.currentRow);
        let lArray = new Array();
        lArray.push(this.currentRow);
        let lJSONObject_business_article_specifications = new Object();
        lJSONObject_business_article_specifications.business_article_specifications =
          lArray; //换表
        let lJSONObject_DataSet = new Object(); // Modify
        lJSONObject_DataSet.Modify =
          lJSONObject_business_article_specifications; //换表
        lJSONObject_DataSet.Add = {
          business_article_log:[{
            Article_Specifications_SerialNumber:this.currentRow.Article_Specifications_SerialNumber,
            Row_Status:"01"
          }]
        }
        // return;
        $.ajax({
          url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
          type: "POST",
          data: {
            Data: JSON.stringify(lJSONObject_DataSet),
          },
          success: function (Result) {
            console.log(Result);
            if (Result.Status === "success") {
              _this.$message({
                message: "提交成功",
                type: "success",
              });
              location.reload();
            } else {
              _this.$message.error("提交失败，请稍后再试");
            }
          },
          complete: function (XMLHttpRequest) {
            requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
          },
          dataType: "json",
        });
      } else if (command === "b") {
        // 不通过操作

        this.$prompt("请输入不通过理由", "提示", {
          type: "warning",
          confirmButtonText: "确定",
          cancelButtonText: "取消",
        })
          .then(({ value }) => {
            console.log(value);
            this.currentRow.Refusal_Reason = value;
            this.currentRow.Row_Status = "88";
            console.log("通过审核:", this.currentRow);
            let lArray = new Array();
            lArray.push(this.currentRow);
            let lJSONObject_business_article_specifications = new Object();
            lJSONObject_business_article_specifications.business_article_specifications =
              lArray; //换表
            let lJSONObject_DataSet = new Object(); // Modify
            lJSONObject_DataSet.Modify =
              lJSONObject_business_article_specifications; //换表
            lJSONObject_DataSet.Add = {
              business_article_log:[{
                Article_Specifications_SerialNumber:this.currentRow.Article_Specifications_SerialNumber,
                Row_Status:"88",
                Refusal_Reason : value
              }]
            }
            // return;
            $.ajax({
              url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
              type: "POST",
              data: {
                Data: JSON.stringify(lJSONObject_DataSet),
              },
              success: function (Result) {
                console.log(Result);
                if (Result.Status === "success") {
                  _this.$message({
                    message: "提交成功",
                    type: "success",
                  });
                  location.reload();
                } else {
                  _this.$message.error("提交失败，请稍后再试");
                }
              },
              complete: function (XMLHttpRequest) {
                requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
              },
              dataType: "json",
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "取消输入",
            });
          });
      } else if (command === "c") {
        this.currentRow.Refusal_Reason = "";
        this.currentRow.Row_Status = "1";
        console.log("上架:", this.currentRow);
        let lArray = new Array();
        lArray.push(this.currentRow);
        let lJSONObject_business_article_specifications = new Object();
        lJSONObject_business_article_specifications.business_article_specifications =
          lArray; //换表
        let lJSONObject_DataSet = new Object(); // Modify
        lJSONObject_DataSet.Modify =
          lJSONObject_business_article_specifications; //换表
        lJSONObject_DataSet.Add = {
          business_article_log:[{
            Article_Specifications_SerialNumber:this.currentRow.Article_Specifications_SerialNumber,
            Row_Status:"1",
          }]
        }
        // return;
        $.ajax({
          url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
          type: "POST",
          data: {
            Data: JSON.stringify(lJSONObject_DataSet),
          },
          success: function (Result) {
            console.log(Result);
            if (Result.Status === "success") {
              _this.$message({
                message: "提交成功",
                type: "success",
              });
              location.reload();
            } else {
              _this.$message.error("提交失败，请稍后再试");
            }
          },
          complete: function (XMLHttpRequest) {
            requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
          },
          dataType: "json",
        });
      } else if (command === "d") {
        this.currentRow.Refusal_Reason = "";
        this.currentRow.Row_Status = "0";
        console.log("重新:", this.currentRow);
        let lArray = new Array();
        lArray.push(this.currentRow);
        let lJSONObject_business_article_specifications = new Object();
        lJSONObject_business_article_specifications.business_article_specifications =
          lArray; //换表
        let lJSONObject_DataSet = new Object(); // Modify
        lJSONObject_DataSet.Modify =
          lJSONObject_business_article_specifications; //换表
        lJSONObject_DataSet.Add = {
          business_article_log:[{
            Article_Specifications_SerialNumber:this.currentRow.Article_Specifications_SerialNumber,
            Row_Status:"0",
          }]
        }
        // return;
        $.ajax({
          url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
          type: "POST",
          data: {
            Data: JSON.stringify(lJSONObject_DataSet),
          },
          success: function (Result) {
            console.log(Result);
            if (Result.Status === "success") {
              _this.$message({
                message: "提交成功",
                type: "success",
              });
              location.reload();
            } else {
              _this.$message.error("提交失败，请稍后再试");
            }
          },
          complete: function (XMLHttpRequest) {
            requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
          },
          dataType: "json",
        });
      }
    },
    selectable(row) {
      return row.Row_Status !== "1";
    },
    xiugai(row) {
      let Article_SerialNumber = sessionStorage.setItem(
        "Article_SerialNumber",
        row.Article_SerialNumber
      );
      window.location.href = "../data/article/edit2.html";
    },
    shanchu(row) {
      // const _this = this;
      // $.ajax({
      //   headers: requestHeaders(),
      //   url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
      //   type: "POST",
      //   data: {
      //     Data: "business_article_specifications",
      //     Condition: "Article_Specifications_SerialNumber='" + row.Article_Specifications_SerialNumber + "'",
      //   },
      //   success: function (data) {
      //     console.log();
      //     data[0].Row_Status = '99'
      //     $.ajax({
      //       headers: requestHeaders(),
      //       type: "POST",
      //       // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
      //       url: `${BASE_URL2}/generalBusiness/generalSave`,
      //       data: {
      //         Data: JSON.stringify({Modify:{
      //           business_article_specifications:data
      //         }})
      //       },
      //       success: function (Result) {
      //         console.log(Result);
      //         _this.qysp(_this.a);
      //       },
      //       complete: function (XMLHttpRequest) {
      //         //   requestPretreatment(XMLHttpRequest);
      //       },
      //       dataType: "json",
      //     });
      //   },
      //   complete: function (XMLHttpRequest) {
      //     requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
      //   },
      //   dataType: "json",
      // });
    },
    shensub() {
      console.log(this.multipleSelection);
      let type = [];
      this.multipleSelection?.forEach((i) => {
        console.log(i);
        i.Row_Status = "1";
        type.push(i);
      });
      console.log(type);
      let lJSONObject_business_article_specifications = new Object();
      lJSONObject_business_article_specifications.business_article_specifications =
        type; //换表
      let lJSONObject_DataSet = new Object(); // Modify
      lJSONObject_DataSet.Modify = lJSONObject_business_article_specifications; //换表
      const _this = this;
      $.ajax({
        // headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
        type: "POST",
        data: {
          Data: JSON.stringify(lJSONObject_DataSet),
        },
        success: function (Result) {
          console.log(Result);
          if (Result.Status === "success") {
            _this.$message({
              message: "提交成功",
              type: "success",
            });
            location.reload();
          } else {
            _this.$message.error("提交失败，请稍后再试");
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    filterTag(value, row) {
      return row.Row_Status === value; //将value的状态值传入
    },
    ArticleTree() {
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        type: "get",
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/clientOperation/getEnterpriseArticleTree",
        data: {},
        success: function (Result) {
          console.log(Result);
          _this.three = Result;
        },
        complete: function (XMLHttpRequest) {
          //   requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    // loadAll() {
    //   const _this = this;
    //   let Enterprise = new Object();
    //   $.ajax({
    //     headers: requestHeaders(),
    //     type: "get",
    //     // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
    //     url: "http://192.168.10.57:8087/get/AllEnterprise",
    //     data: {
    //       pageSize: 15,
    //       pageNumber: 1,
    //     },
    //     success: function (Result) {
    //       console.log(Result, "loadAll");
    //       for (let index = 0; index < Result.Data.length; index++) {
    //         Enterprise = Result.Data[index].Enterprise_Name;
    //       }
    //       // Enterprise_Name = Result.Data;
    //       //   that.total = Result.TotalRows;
    //     },
    //     complete: function (XMLHttpRequest) {
    //       //   requestPretreatment(XMLHttpRequest);
    //     },
    //     dataType: "json",
    //   });
    //   console.log(Enterprise);
    //   return Enterprise;
    // },
    querySearchAsync(queryString, cb) {
      var restaurants = this.restaurants;
      var results = queryString
        ? restaurants.filter(this.createStateFilter(queryString))
        : restaurants;

      clearTimeout(this.timeout);
      this.timeout = setTimeout(() => {
        cb(results);
      }, 3000 * Math.random());
    },
    //value替代
    createStateFilter(queryString) {
      return (state) => {
        return (
          state.Enterprise_Name.toLowerCase().indexOf(
            queryString.toLowerCase()
          ) === 0
        );
      };
    },
    handleSelect(item) {
      console.log(item);
    },
    handleNodeClick(data) {
      console.log(data);
      this.Enterprise_Number = data.Enterprise_Number;
      this.form.Condition = window.btoa(unescape(encodeURIComponent( this.Enterprise_Number + ",%%")))
      // this.a = data;
      // data.PageNubmer = this.ye;
      // data.RowAmount = 6;
      this.qysp(this.form);
    },
    qysp(data) {
      // console.log(res);
      const _this = this;
      // let pageNumber = res.PageNubmer;
      // _this.loading = false;
      // let Enterprise_Info_SerialNumber = res.Enterprise_Number;
      // _this.tableData = Result.Rows;
      $.ajax({
        headers: requestHeaders(),
        type: "POST",
        url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        // url: "https://service.kdddy.cn/donghui/login/generalQueryByTableNameAndPaginationForClient",
        data,
        success: function (Result) {
          // console.log(Result);
          _this.total = Result.TotalRows;
          _this.tableData = Result.Rows;
        },
        complete: function (XMLHttpRequest) {
          //   requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
      // $.ajax({
      //   headers: {
      //     contentType: "application/json", // 设置请求体的媒体类型为application/json
      //     AccessToken: $.cookie("token"), //会将数据转换为query string
      //   },
      //   type: "get",
      //   // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
      //   url: "https://service.kdddy.cn/donghuiForRequest/Specification",
      //   data: {
      //     pageSize: 6,
      //     pageNumber: pageNumber,
      //     Enterprise_Info_SerialNumber: Enterprise_Info_SerialNumber, //表名
      //   },
      //   success: function (res) {
      //     console.log(res);
      //     _this.tableData = res.Data;
      //     _this.total = res.total;
      //   },
      //   complete: function (XMLHttpRequest) {
      //     //   requestPretreatment(XMLHttpRequest);
      //   },
      //   dataType: "json",
      // });
      // },
      //   complete: function (XMLHttpRequest) {
      //     // requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
      //   },
      //   dataType: "json",
      // });
    },
    handleEdit(index, row) {
      //#99
      let Article_SerialNumber = sessionStorage.setItem(
        "Article_SerialNumber",
        row.Article_SerialNumber
      );

      window.location.href = "./edit2.html";
      console.log(index, row);
    },
    //#100
    handleDelete(index, row) {
      const _this = this;
      console.log(index, row);
      row.Row_Status = "1";
      console.log(row);
      delete row.Operation_Datetime;
      delete row.Operation_Datetime_Original;
      delete row.Operation_ID;
      delete row.Operation_ID_Original;
      let lArray = new Array();
      lArray.push(row);
      let lJSONObject_business_article_info = new Object();
      lJSONObject_business_article_info.business_article_info = lArray; //换表
      let lJSONObject_DataSet = new Object();
      lJSONObject_DataSet.Modify = lJSONObject_business_article_info;
      console.log(lJSONObject_DataSet);

      $.ajax({
        // headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
        type: "POST",
        data: {
          Data: JSON.stringify(lJSONObject_DataSet),
        },
        success: function (Result) {
          console.log(Result);
          if (Result.Status == "success") {
            _this.tableData.splice(index, 1);
          }
        },
        complete: function (XMLHttpRequest) {
          // requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    //查询企业信息和个人信息
    dhcph() {
      console.log(this.UserID);
      let Arg_UserID = this.UserID;
      const _this = this;
      $.ajax({
        // headers: requestHeaders(),
        url: "https://service.kdddy.cn/donghuiForRequest/selectByData/selectEnterpriseID",
        type: "get",
        data: {
          Data: Arg_UserID,
        },
        success: function (Result) {
          console.log(Result.Data[0].Enterprise_Info_SerialNumber);
          let qybh = Result.Data[0].Enterprise_Info_SerialNumber;
          _this.getList(qybh);
        },
        complete: function (XMLHttpRequest) {
          // requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    //所有上传的预包装商品
    getList(res) {
      console.log(res, "getList");
      const _this = this;
      $.ajax({
        // headers: requestHeaders(),
        // url: "http://192.168.10.57:8087/prePrePackaged/ALL",
        url: "https://service.kdddy.cn/donghuiForRequest/prePrePackaged/ALL",
        type: "get",
        data: {
          pageSize: 15,
          pageNumber: 1,
          Status: "0",
        },
        success: function (Result) {
          console.log(Result);
          _this.tableData = Result.Data;
          _this.total = Result.total;
        },
        complete: function (XMLHttpRequest) {
          // requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },

    onSerach() {
      //查询方法
      this.form.PaginationNumber = 1;
      this.getList(this.form);
    },
    examine() {
      //审核
      window.location.href = "./examine.html";
    },
    log() {
      window.location.href = "./log.html";
    },
    Add() {
      window.location.href = "./add.html";
    },
    Show(Article_SerialNumber) {
      this.Article_SerialNumber = Article_SerialNumber;
      this.dialogVisible = true;
    },
    handleSizeChange(val) {
      this.form.PaginationNumber = 1;
      this.form.RowAmount = val;
      this.getList(this.form);
    },
    handleCurrentChange(val) {
      this.form.PaginationNumber = val;
      this.getList(this.form);
    },
    handleBatchAdd(command) {
      const that = this;
      if (this.multipleSelection.length > 0) {
        this.$confirm(
          command == "0" ? "是否将勾选的商品下架?" : "是否将勾选的商品上架",
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "info",
          }
        )
          .then(() => {
            //1.遍历已选查询对应数据
            let Shelf_Date = getYMDHMSDate();
            let Condition = "";
            this.multipleSelection
              .filter((i) => i.Shelf == command)
              .forEach((item) => {
                if (Condition) {
                  Condition =
                    Condition +
                    " OR Article_SerialNumber='" +
                    item.Article_SerialNumber +
                    "'";
                } else {
                  Condition =
                    "Article_SerialNumber='" + item.Article_SerialNumber + "'";
                }
              });
            $.ajax({
              headers: requestHeaders(),
              url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
              type: "POST",
              data: {
                Data: "business_article_info",
                Condition,
              },
              success: function (business_article_info) {
                let base_operation_log = [];
                business_article_info.forEach((item) => {
                  item.Shelf = command == "0" ? "1" : "0";
                  item.Shelf_Date = Shelf_Date;
                  base_operation_log.push(
                    generateLog(
                      "商品:" +
                        that.multipleSelection.filter(
                          (i) =>
                            i.Article_SerialNumber == item.Article_SerialNumber
                        )[0].Article_Name +
                        (command == "0" ? "下" : "上") +
                        "架",
                      "平台端操作",
                      "business_article_info",
                      JSON.stringify({
                        Modify: { business_article_info: item },
                      })
                    )
                  );
                });
                $.ajax({
                  headers: requestHeaders(),
                  url: `${BASE_URL2}/generalBusiness/generalSave`,
                  type: "POST",
                  data: {
                    Data: JSON.stringify({
                      Modify: { business_article_info },
                      Add: { base_operation_log },
                    }),
                  },
                  success: function (res) {
                    if (res.Status === "success") {
                      that.$message({
                        type: "success",
                        message: "操作成功!",
                      });
                      that.getList(that.form);
                    } else {
                      that.$message.error("删除失败，请稍后再试");
                    }
                  },
                  error: function () {
                    that.$message.error("删除失败，请稍后再试");
                  },
                  complete: function (XMLHttpRequest) {
                    that.loading = false;
                    // requestPretreatment(XMLHttpRequest);
                  },
                  dataType: "json",
                });
              },
              error: function () {
                that.$message.error("删除失败，请稍后再试");
              },
              complete: function (XMLHttpRequest) {
                that.loading = false;
                // requestPretreatment(XMLHttpRequest);
              },
              dataType: "json",
            });
          })
          .catch(() => {});
      } else {
        this.$message({
          type: "warning",
          message: "至少要选择1个商品!",
        });
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // downloadTemplate(command) {
    //   if (command == "Article") {
    //     window.location.href = "./download/导入商品模板表.新.xlsx";
    //   } else if (command == "BarCode") {
    //     window.location.href = "./download/导入条形码模板.xlsx";
    //   } else if (command == "UpData") {
    //     window.location.href = "./download/更新商品模板.xlsx";
    //   }
    // },
    importTemplate(command) {
      if (command == "Article") {
        // window.location.href = './import_article.html';
        window.location.href = "./import1.html";
      } else if (command == "BarCode") {
        window.location.href = "./import_barcode.html";
      } else if (command == "UpData") {
        window.location.href = "./import_edit.html";
      }
    },
    moreConfig(command, row) {
      if (command == "Edit") {
        this.Edit(row.Article_SerialNumber);
      } else if (command == "Remove") {
        this.Remove(row);
      } else if (command == "Download0") {
        this.Download0(row.Article_SerialNumber);
      } else if (command == "Download1") {
        this.Download1(row.Article_SerialNumber);
      } else if (command == "Shelf") {
        const that = this;
        let obj = deepClone(row);
        console.log(obj);
        this.$confirm(
          `是否要${obj.Shelf == "0" ? "下" : "上"}架该商品继续?`,
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        )
          .then(() => {
            obj.Shelf_Date = getYMDHMSDate();
            $.ajax({
              headers: requestHeaders(),
              url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
              type: "POST",
              data: {
                Data: "business_article_info",
                Condition:
                  "Article_SerialNumber='" + row.Article_SerialNumber + "'",
              },
              success: function (data) {
                if (obj.Shelf == "0") {
                  data[0].Shelf = "1";
                } else {
                  data[0].Shelf = "0";
                }
                $.ajax({
                  headers: requestHeaders(),
                  url: `${BASE_URL2}/generalBusiness/generalSave`,
                  type: "POST",
                  data: {
                    Data: JSON.stringify({
                      Modify: { business_article_info: data },
                      Add: {
                        base_operation_log: [
                          generateLog(
                            "商品:" +
                              obj.Article_Name +
                              (obj.Shelf == "0" ? "下" : "上") +
                              "架",
                            "平台端操作",
                            "business_article_info",
                            JSON.stringify({
                              Modify: { business_article_info: data },
                            })
                          ),
                        ],
                      },
                    }),
                  },
                  success: function (res) {
                    if (res.Status === "success") {
                      that.$message({
                        type: "success",
                        message: "操作成功!",
                      });
                      that.getList(that.form);
                    } else {
                      that.$message.error("删除失败，请稍后再试");
                    }
                  },
                  error: function () {
                    that.$message.error("删除失败，请稍后再试");
                  },
                  complete: function (XMLHttpRequest) {
                    that.loading = false;
                    // requestPretreatment(XMLHttpRequest);
                  },
                  dataType: "json",
                });
              },
              error: function () {
                that.$message.error("删除失败，请稍后再试");
              },
              complete: function (XMLHttpRequest) {
                that.loading = false;
                // requestPretreatment(XMLHttpRequest);
              },
              dataType: "json",
            });
          })
          .catch(() => {});
      }
    },
    Download0(Article_SerialNumber) {
      //下载主图
      const that = this;
      $.ajax({
        headers: requestHeaders(),
        type: "POST",
        url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
        data: {
          Data: "business_article_pic",
          Condition:
            "Article_SerialNumber='" +
            Article_SerialNumber +
            "' and Row_Status='0' and Picture_Type='0'",
        },
        success: function (Result) {
          let Files = "";
          Result.forEach((item) => {
            if (Files) {
              Files = Files + "," + item.Picture_URL;
            } else {
              Files = item.Picture_URL;
            }
          });
          const url = `${BASE_URL2}/login/downloadZipFile?Files=${Files}`;
          const a = document.createElement("a");
          a.style.display = "none";
          a.href = url;
          document.body.appendChild(a);
          a.click(); // 触发点击
          a.remove();
        },
        complete: function (XMLHttpRequest) {
          // requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    Download1(Article_SerialNumber) {
      //下载详情图
      $.ajax({
        headers: requestHeaders(),
        type: "POST",
        url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
        data: {
          Data: "business_article_pic",
          Condition:
            "Article_SerialNumber='" +
            Article_SerialNumber +
            "' and Row_Status='0' and Picture_Type='1'",
        },
        success: function (Result) {
          let Files = "";
          Result.forEach((item) => {
            if (Files) {
              Files = Files + "," + item.Picture_URL;
            } else {
              Files = item.Picture_URL;
            }
          });
          const url = `${BASE_URL2}/login/downloadZipFile?Files=${Files}`;
          const a = document.createElement("a");
          a.style.display = "none";
          a.href = url;
          document.body.appendChild(a);
          a.click(); // 触发点击
          a.remove();
        },
        complete: function (XMLHttpRequest) {
          // requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    downloadAddTemplate() {
      //新增商品模板
      window.location.href = "./download/导入商品模板表.xlsx";
    },
    downloadEditTemplate() {
      //更新商品模板
      window.location.href = "./download/更新商品信息导入模板表.xlsx";
    },
    Edit(Article_SerialNumber) {
      sessionStorage.setItem("Article_SerialNumber", Article_SerialNumber);
      window.location.href =
        "./edit.html?Article_SerialNumber=" + Article_SerialNumber;
    },
    Remove(row) {
      const that = this;
      this.$confirm("警告！此操作将删除该商品, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          row.Row_Status = "1";
          $.ajax({
            headers: requestHeaders(),
            url: `${BASE_URL2}/generalBusiness/generalSave`,
            type: "POST",
            data: {
              Data: JSON.stringify({
                Modify: { business_article_info: [row] },
                Add: {
                  base_operation_log: [
                    generateLog(
                      "删除商品信息",
                      "平台端操作",
                      "business_article_info",
                      JSON.stringify({
                        Modify: { business_article_info: [row] },
                      })
                    ),
                  ],
                },
              }),
            },
            success: function (res) {
              if (res.Status === "success") {
                that.$message({
                  type: "success",
                  message: "删除成功!",
                });
                that.getList(that.form);
              } else {
                that.$message.error("删除失败，请稍后再试");
              }
            },
            error: function () {
              that.$message.error("删除失败，请稍后再试");
            },
            complete: function (XMLHttpRequest) {
              that.loading = false;
              requestPretreatment(XMLHttpRequest);
            },
            dataType: "json",
          });
        })
        .catch(() => {});
    },
    Export(form) {
      const that = this;
      this.loading = true;
      let data = deepClone(form);
      data.SQLSerialNumber = "P_business_supplier_article1";
      data.Condition = "";
      data.ExtensionCondition = "";
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalQueryBySQLSerialNumber`,
        type: "POST",
        data,
        success: function (Result) {
          if (Result.length > 0) {
            const wb = XLSX.utils.book_new();
            const ws_data = [
              [
                "商品内码",
                "商品名称",
                "品牌",
                "分类",
                "史泰博编码",
                "封面图",
                "品牌内码",
                "规格内码",
                "规格",
                "规格封面",
                "规格京东价格",
                "规格京东链接",
                "供应商",
                "供应商编号",
                "销售价格",
                "采购价格",
                "每日库存",
                "上架状态",
                "可适用积分",
                "抵扣类型",
                "抵扣比例",
                "是否参与团购",
                "活动价格",
              ],
            ];
            Result.forEach((item) => {
              ws_data.push([
                item.Article_SerialNumber,
                item.Article_Name,
                item.Brand_Name,
                item.Classify_Name,
                item.Staples_Code,
                BASE_IMG + item.Picture_URL,
                item.Brand_SerialNumber,
                item.Article_Specifications_SerialNumber,
                item.Specifications_Name,
                BASE_IMG + item.Picture_URL1,
                item.JDCOM_Unit_Price,
                item.JDCOM_URL,
                item.Supplier_Name,
                item.Supplier_SerialNumber,
                item.Sales_Unit_Price,
                item.Purchase_Unit_Price,
                item.Total_stock,
                item.Shelf == "0" ? "上架" : "下架",
                item.Cash_Point == "0" ? "现金积分" : "",
                item.Deduction_Type == "0" ? "固定抵扣" : "百分比",
                item.Deduction_Limit,
                item.Group,
                item.Activity_Unit_Price,
              ]);
            });
            const ws = XLSX.utils.aoa_to_sheet(ws_data);
            ws["!cols"] = [];
            ws_data[0].forEach((item) => {
              ws["!cols"].push({
                alignment: { horizontal: "center" },
                wpx: 150,
              });
            });
            XLSX.utils.book_append_sheet(wb, ws, "商品信息");
            XLSX.writeFile(wb, "商品信息" + +new Date() + ".xlsx");
            that.$message({
              message: "已导出商品信息！",
              type: "success",
            });
          } else {
            that.$message({
              message: "暂无可导出的数据",
              type: "warning",
            });
          }
        },
        complete: function (XMLHttpRequest) {
          that.loading = false;
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
  },
});
